define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wanlshop.address_spot/index' + location.search,
                    add_url: 'wanlshop.address_spot/add',
                    edit_url: 'wanlshop.address_spot/edit',
                    del_url: 'wanlshop.address_spot/del',
                    multi_url: 'wanlshop.address_spot/multi',
                    import_url: 'wanlshop.address_spot/import',
                    table: 'wanlshop_address_spot',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'spot_type', title: __('类型'),searchList: {"0":__('商户'),"1":__('个人')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('自提点名称'),operate: 'LIKE'},
                        {field: 'img',title: __('自提点照片'),operate:false,events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'contacts',title: __('联系人'),operate: 'LIKE'},
                        {field: 'phone',title: __('联系电话'),operate: 'LIKE'},
                        {field: 'address',title: __('门店位置'),operate: 'LIKE'},
                        {field: 'time',title: __('下单后可取时间'),operate: 'LIKE'},
                        {field: 'createtime',title: __('创建时间'),operate: 'RANGE',addclass: 'datetimerange',formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'), searchList: {"0":__('隐藏'),"1":__('正常'),"2":__('认证中'),"3":__('认证失败'),"4":__('待签约')},custom: {'0':'danger','1':'success','2':'info','3':'danger','4':'info'}, formatter: Table.api.formatter.status},
                        {field: 'operate',
                            title: __('Operate'),table: table,
                            events: Table.api.events.operate,
                            // buttons: [
                            //     {name: '查看认证状态',text: __('查看认证状态'),classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',url: 'wanlshop/freight/restore',refresh: true},
                            //     {name: '重新提交',text: __('重新提交'),classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',url: 'wanlshop/freight/destroy',refresh: true}
                            // ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'wanlshop.address_spot/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('自提点名称'),operate: 'LIKE'},
                        {field: 'img',title: __('自提点照片'),operate:false,events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'contacts',title: __('联系人'),operate: 'LIKE'},
                        {field: 'phone',title: __('联系电话'),operate: 'LIKE'},
                        {field: 'address',title: __('门店位置'),operate: 'LIKE'},
                        {field: 'time',title: __('下单后可取时间'),operate: 'LIKE'},
                        {field: 'createtime',title: __('创建时间'),operate: 'RANGE',addclass: 'datetimerange',formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'), searchList: {"0":__('隐藏'),"1":__('正常'),"2":__('认证中'),"3":__('认证失败'),"4":__('待签约')},custom: {'0':'danger','1':'success','2':'info','3':'danger','4':'info'}, formatter: Table.api.formatter.status},
                        {field: 'operate',width: '130px',title: __('Operate'),table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {name: 'Restore',text: __('还原'),classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',icon: 'fa fa-rotate-left',url: 'wanlshop.address_spot/restore',refresh: true},
                                {name: 'Destroy',text: __('彻底删除'),classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',icon: 'fa fa-times',url: 'wanlshop.address_spot/destroy',refresh: true}
                            ],formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        withdraw: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wanlshop.address_spot/withdraw' + location.search,
                    add_url: 'wanlshop.address_spot/add_withdraw',
                    edit_url: 'wanlshop.address_spot/edit_withdraw',
                    del_url: 'wanlshop.address_spot/del',
                    multi_url: 'wanlshop.address_spot/multi',
                    import_url: 'wanlshop.address_spot/import',
                    table: 'wanlshop_address_spot',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('核销门店'),operate: 'LIKE'},
                        {field: 'img',title: __('门店照片'),operate:false,events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'contacts',title: __('联系人'),operate: 'LIKE'},
                        {field: 'phone',title: __('联系电话'),operate: 'LIKE'},
                        {field: 'address',title: __('门店位置'),operate: 'LIKE'},
                        {field: 'start_time',title: __('营业时间开始'),operate: false},
                        {field: 'end_time',title: __('营业时间开始'),operate: false},
                        {field: 'createtime',title: __('创建时间'),operate: 'RANGE',addclass: 'datetimerange',formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'), searchList: {"0":__('隐藏'),"1":__('正常'),"2":__('认证中'),"3":__('认证失败'),"4":__('待签约')},custom: {'0':'danger','1':'success','2':'info','3':'danger','4':'info'}, formatter: Table.api.formatter.status},
                        {field: 'operate',
                            title: __('Operate'),table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin_withdraw: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");


            // 初始化表格
            table.bootstrapTable({
                url:'wanlshop.address_spot/recyclebin_withdraw' + location.search,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('核销门店'),operate: 'LIKE'},
                        {field: 'img',title: __('门店照片'),operate:false,events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'contacts',title: __('联系人'),operate: 'LIKE'},
                        {field: 'phone',title: __('联系电话'),operate: 'LIKE'},
                        {field: 'address',title: __('门店位置'),operate: 'LIKE'},
                        {field: 'start_time',title: __('营业时间开始'),operate: false},
                        {field: 'end_time',title: __('营业时间开始'),operate: false},
                        {field: 'createtime',title: __('创建时间'),operate: 'RANGE',addclass: 'datetimerange',formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'), searchList: {"0":__('隐藏'),"1":__('正常'),"2":__('认证中'),"3":__('认证失败'),"4":__('待签约')},custom: {'0':'danger','1':'success','2':'info','3':'danger','4':'info'}, formatter: Table.api.formatter.status},
                        {field: 'operate',width: '130px',title: __('Operate'),table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {name: 'Restore',text: __('还原'),classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',icon: 'fa fa-rotate-left',url: 'wanlshop.address_spot/restore',refresh: true},
                                {name: 'Destroy',text: __('彻底删除'),classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',icon: 'fa fa-times',url: 'wanlshop.address_spot/destroy',refresh: true}
                            ],formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            // Controller.detailInit('add');
        },
        add_withdraw: function () {
            Controller.api.bindevent();
            // Controller.detailInit('add');
        },
        edit_withdraw: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
